package org.czl.tree;

public class lll {
    public static void main(String[] args) {
        maximumsSplicedArray(new int[]{60,60,60}, new int[]{10,90,10});
    }
    public static int maximumsSplicedArray(int[] nums1, int[] nums2) {
        return Math.max(f(nums1, nums2), f(nums2, nums1));
    }
   static int f(int[] nums1, int[] nums2){
        int n = nums1.length;
        int max = 0;
        int sum = 0;
        int[] nums3 = new int[n];
        for(int i = 0; i< n;i++){
            nums3[i] = nums2[i] - nums1[i];
        }
        int all = 0;
        int[] dp = new int[n + 1];
        dp[0] = nums3[0];
        for(int i = 1; i <= n; i++){
            sum += nums1[i - 1];
            dp[i] = Math.max(dp[i - 1] + nums3[i - 1], nums3[i - 1]);
            max = Math.max(max, dp[i]);
        }
        return sum + max;
    }
}
